import { http } from '@/utils/request'
import { AddFormType, ClientType, ContactReturnType, CustomerListType, FabType, MethodSetting, SubMitType, WordOrderRequestType, WorkOrderListType, WorkOrderType } from './type'

export const getWorkOrderList = (data: WordOrderRequestType) => {
    return http.post<WorkOrderListType>('/ticket/all_ticket', data)
}

//通知方法设定回显数据
export const getNotification = () => {
    return http.get<{ statusCode: number, message: string, notify_options: MethodSetting[] }>('/user/notify_method')
}

//通知方法设定提交
export const notificationSubmit = (data: { notify_options: MethodSetting[] }) => {
    return http.post('/user/notify_method', data)
}

//修改密码
export const changePassword = (data: { username: string, new_password: string | null }) => {
    return http.post<{ message: string, statusCode: number }>('/user/update_password', data)
}

//新增获取客信息
export const getClient = () => {
    return http.post<ClientType>('/ticket/ticket')
}

//通过FAB请求客户联系人列表
export const getFabList = (data: { customer_id: number }) => {
    return http.post<FabType>('/ticket/information', data)
}

//通过FAB获取客户设备编号
export const workDeviceNumber = (data: { customer_id: number }) => {
    return http.post<{ device_list: CustomerListType[] }>('/ticket/device', data)
}

//工单分类获取负责人和To
export const workClassify = (data: { customer: null | string | number, ticket_type: number | null, ticket_cate: number }) => {
    return http.post<{ data: { id: number, name: string } }>('/ticket/to', data)
}

//通过客户联系人获取电话和邮箱
export const getContactPhone = (data: { id: number }) => {
    return http.post<{ phone_number: string, email_address: string }>('/ticket/get_user_info', data)
}

//通过客户设备编号获取对应数据
export const getDeviceNumber = (data: { device_sn_cust: number }) => {
    return http.post<{ data: { device_type: string, device_sn: string, device_warranty: string, component_warranty: string } }>('/ticket/device_info', data)
}

//附件上传
export const workAttachmentUpload = (data: { file_name: string, type: string }) => {
    const formData = new FormData()

    formData.append('file_name', data.file_name)

    formData.append('type', data.type)

    return http.post<{ file_path: string, upload_url: string }>('/ticket/upload', formData)
}

//附件下载
export const workAttachmentDownload = (data: { file_path: string }) => {
    return http.post<{ download_url: string }>('/ticket/down_upload', data)
}

//通讯录列表
export const getContactsList = (data: { action: string, operate_type: string, customer_id: number | null | undefined, ticket_number: null | number | undefined }) => {
    return http.post<ContactReturnType>('/ticket/show_user', data)
}

//取消，设为常用
export const contactsAddSave = (data: { ids: string, action: string }) => {
    // action:add 设为常用  remove  取消常用
    return http.post('/ticket/toggle', data)
}

//新增提交
export const getFrom = (data: AddFormType) => {
    return http.post('/ticket/create_ticket', data)
}

//详情回显
export const workEditEcho = (data: { ticket_number: string }) => {
    return http.post('/ticket/ticket_detail', data)
}

//留言提交接口
export const workSure = (data: any) => {
    return http.post('/ticket/message_ticket', data)
}

//按钮新增接口
export const workOrderSure = (data: any) => {
    return http.post('/ticket/operation', data)
}

//修改提交，确认提交保存
export const workFormView = (data: SubMitType) => {
    return http.post('/ticket/commit_ticket', data)
}

//Ai搜索
export const getSearch = (data: { question: string }) => {
    return http.post<{ message: string, statusCode: number, data: WorkOrderType }>('/search/search', data)
}

//列表
export const getSearchAllList = (data: { type: string, question: string, page_number: number, page_size: number }) => {
    return http.post('/search/search_all', data)
}

